/*
  Copyright 2011 fullkawa

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package jp.fullkawa.ksp2html;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.util.Properties;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import jp.fullkawa.xnovel.XNovel;

public class HTMLBuilder
{
	public static BufferedWriter getXNovelWriter(XNovel xnovel, OutputStreamWriter output)
	{
		// Writer writer = new StringWriter();
		BufferedWriter writer = new BufferedWriter(output);

		Properties p = new Properties();
		p.setProperty("file.resource.loader.path", "., ./lib, ./target/test-classes");
		Velocity.init(p);

		VelocityContext context = new VelocityContext();
		context.put("xnovel", xnovel);

		Template template = Velocity.getTemplate("xnovel.vm", "UTF-8");
		template.merge(context, writer);

		return writer;
	}
}
